#include "sys_stdio.h"
#include "task_manager.h"
#include "input_task.h"
#include "main_task.h"
#include "gpio.h"

struct gs_input_task
{
    struct sj_task_t input_task_handle;
    sj_int8 fd_key;
    struct input_init_param param;
};
static struct gs_input_task gs_input_task_all = {0};

static TASK_MODULE_DATA(input,INPUT_TASK_PRIO,INPUT_STK_SIZE);

void input_task_init(struct input_init_param *param)
{
    gs_input_task_all.param = *param;
    gs_input_task_all.input_task_handle.name="input";
    gs_input_task_all.input_task_handle.run_func = input_task;
    GET_TASK_MODULE_DATA(gs_input_task_all.input_task_handle.task_data,input);
    sj_task_create(&gs_input_task_all.input_task_handle);
    gs_input_task_all.fd_key = sj_open("/dev/input",0);
}

void input_task(void *arg)
{
    sj_int8 value=0;
    int ret = sj_poll(gs_input_task_all.fd_key,500);
    if(ret==0)
    {

    }
    else if(ret==1)
    {
        sj_read(gs_input_task_all.fd_key,&value,1);
        if(gs_input_task_all.param.control_run)
        {
            gs_input_task_all.param.control_run(value);
        }
    }
}
